#ifndef MONITORPRO_SEGMENT_H
#define MONITORPRO_SEGMENT_H

#define VERSION_8 8

#include <string>
#include <vector>
#include <unistd.h>

#include "cross_process_bag.h"
#include "span.h"


class Segment
{
public:
    Segment(const std::string &serviceId, const std::string &serviceInstanceId, int version, const std::string &header);
    ~Segment();

    Span *createSpan(SkySpanType type, SkySpanLayer layer, int componentId);
    Span *getLastSpan();
    std::string marshal();
    void setStatusCode(int code);
    std::string createHeader(Span *span);
    void createRefs();
    std::string getTraceId();

private:
    CrossProcessBag *bag;

    std::string _traceId;
    std::string _traceSegmentId;
    std::vector<Span *> spans;
    int _version;
    std::string _header;
    std::string _serviceId;
    std::string _serviceInstanceId;
    bool isSizeLimited = false;

    int _status_code = 200;
};

#endif